package com.skill.shareskill.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.skill.shareskill.R;
import com.skill.shareskill.bean.ActivityItem;
import com.skill.shareskill.utils.HttpUtils;
import java.util.List;

/**
 * Created by Administrator on 2018/1/29 0029.
 */

public class ActivityItemAdapter extends BaseAdapter{
    private List<ActivityItem> ActivityItem;
    private Context context ;
    public ActivityItemAdapter(Context context ,List<ActivityItem> ActivityItem) {
        // TODO Auto-generated constructor stub
        this.ActivityItem = ActivityItem;
        this.context = context;
    }
    public int getCount() {
        // TODO Auto-generated method stub
        return ActivityItem.size();
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View view = null;
        ViewHolder holder = null;
        if(convertView==null){
            view = View.inflate(context, R.layout.list_item_activity, null);
            holder = new ViewHolder();
            holder.iv_image=view.findViewById(R.id.iv_image);
            holder.tv_title=view.findViewById(R.id.tv_title);
            holder.tv_price=view.findViewById(R.id.tv_price);
            view.setTag(holder);
        }else{
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }

        ActivityItem item = ActivityItem.get(position);
        holder.tv_title.setText(item.getActDescribe());
        holder.tv_price.setText(item.getActPrice()+" ");
        //http://192.168.40.201:8080/NetworkWeb/图片路径
        Glide.with(context)
                .load(HttpUtils.BASE_PATH+item.getActImg())
                .placeholder(R.drawable.pic1)
                .error(R.drawable.pic2)
                .into(holder.iv_image);
        //holder.iv_image.setImageUrl(HttpUtils.BASE_PATH+item.getActImg(),400,200);
        return view;
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    class ViewHolder{
        ImageView iv_image;
        TextView tv_title;
        TextView tv_price;
    }

}
